<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/fragments/head">
<title>角色管理</title>
</head>
<body class="hold-transition skin-blue sidebar-mini">
	<div class="wrapper">

		<div th:replace="admin/fragments/header"></div>
		<div th:replace="admin/fragments/mainsidebar::mainside('角色管理','role')"></div>

		<div class="content-wrapper">

			<section class="content-header">
				<h1>角色管理</h1>
			</section>

			<section class="content">

				<div class="box box-primary">
					<div class="box-header">
						<a class="btn btn-sm btn-success" href="/admin/role/add">新增</a>
					</div>
					<div class="box-body">
						<table id="resourceTab" class="table table-bordered table-striped">
							<thead>
								<tr>
									<th>角色名称</th>
									<th>角色key</th>
									<th>操作</th>
								</tr>
							</thead>
						</table>
					</div>

				</div>
			</section>
		</div>

		<div th:replace="admin/fragments/footer"></div>
	</div>

	<div th:replace="admin/fragments/script"></div>
	<script>
		function del(id) {
			layer.confirm('确定删除吗?', {
				icon : 3,
				title : '提示'
			}, function(index) {
				$.ajax({
					type : "POST",
					dataType : "json",
					url : "/admin/role/delete/" + id,
					success : function(res) {
						layer.msg(res.message, {
							time : 2000
						}, function() {
							location.reload();
						});
					}
				});
			});
		}

		$(document)
				.ready(
						function() {
							$('#resourceTab')
									.DataTable(
											{
												language : {
													url : '/assets/plugins/datatables.net/Chinese.json'
												},
												processing : true,
												serverSide : false,
												ajax : {
													url : "/admin/role/list",
													type : "POST"
												},
												columns : [ {
													data : 'roleName'
												}, {
													data : 'roleKey'
												}, {
													data : null
												} ],
												columnDefs : [
														{
															render : function(
																	data, type,
																	row) {
																return '<a class="btn btn-sm btn-success" href="/admin/role/edit/'+row.id+'">修改</a> <a class="btn btn-sm btn-warning" href="/admin/role/grant/'+row.id+'">分配资源</a> <button class="btn btn-sm btn-danger" onclick="del('
																		+ row.id
																		+ ')">删除</button>';
															},
															targets : -1
														},
														{
															"orderable" : false,
															"targets" : -1
														},
														{
															"searchable" : false,
															"targets" : -1
														} ]
											});
						});
	</script>
</body>
</html>